package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: wx
 * Date: 2023-12-15
 * Time: 20:06
 */
public class ThreadDemo17 {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                System.out.println("线程正在运行中...");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

        //线程启动前, 状态就是 NEW
        /* 一个 Thraed 对象只能 start一次
         和线程状态密切相关
         只有处于new状态才能start*/
        System.out.println(t1.getState());
        t1.start();
        t1.join();
        // 线程运行完毕之后就是 TERMINATED
        System.out.println(t1.getState());
    }
}
